<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/static/lib/layui-v2.8.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/index/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">房间类型</label>
        <div class="layui-input-block">
            <select name="roomType" lay-verify="required" lay-search="" lay-reqtext="房间类型不能为空">
                <option value="">请选择房间类型</option>
                <option th:each="roomType : ${roomTypes}" th:value="${roomType.id}" th:text="${roomType.type}"></option>
            </select>
<!--            <input type="text" name="roomType" lay-verify="required|roomType" lay-reqtext="房间类型不能为空" placeholder="请输入房间类型" value="" class="layui-input">-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">楼层</label>
        <div class="layui-input-block">
            <select name="floor" lay-verify="required" lay-search="" lay-reqtext="楼层不能为空">
                <option value="">请选择楼层</option>
                <option th:each="floor : ${floors}" th:value="${floor.value}" th:text="${floor.name}"></option>
            </select>
<!--            <input type="text" name="floor" lay-verify="required|floor" lay-reqtext="楼层不能为空" placeholder="请输入楼层" value="" class="layui-input">-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">房间号</label>
        <div class="layui-input-block">
            <input type="text" name="roomNum" lay-verify="required|roomNum" lay-reqtext="房间号不能为空" placeholder="请输入房间号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    let ctx = '[[${#httpServletRequest.getContextPath()}]]';
</script>
<script th:src="@{/static/lib/layui-v2.8.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/static/lib/captcha/js/crypto-js.js}" charset="utf-8"></script>
<script th:src="@{/static/lib/captcha/js/ase.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data = data.field;

            // 发送请求
            fetch(ctx + '/room/add',{
                headers: {
                    'Content-Type': 'application/json'
                },
                method: 'POST',
                body: JSON.stringify(data)
            }).then(function (resp){
                return resp.json();
            }).then(function(json){
                if (json.code == 200){
                    var index = layer.alert('添加成功', {
                        title: '操作成功',
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);

                        // 刷新父页面表格
                        parent.layui.table.reload('currentTableId');

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                    });
                } else {
                    layer.msg(json.msg, {icon: 2, time: 1000});
                }
            }).catch(function (error) {
                layer.msg(error.msg, {icon: 2, time: 1000});
            });



            return false;
        });
    });
</script>
</body>
</html>